package com.lagou.numbersort.step2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class NumSortReducer2 extends Reducer<Text, LongWritable, Text, LongWritable> {
    LongWritable v = new LongWritable();
    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        //累加获得每个分区中的数字个数
        long sum = 0L;
        for (LongWritable value : values) {
            sum += value.get();
        }
        v.set(sum);

        context.write(key,v);
    }
}
